package com.hotel.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hotel.entity.CheckOut;
import com.hotel.entity.HouseStatement;
import com.hotel.service.CheckOutService;
import com.hotel.service.HouseStatementService;
import com.hotel.utils.JsonUtils;

@Controller
public class StatementController {
	
	@Autowired
	private CheckOutService checkOutService;
	
	@Autowired
	private HouseStatementService houseStatementService;
	
	/**
	 * 年度报表
	 * @return
	 */
	@RequestMapping(value="annualStatement")
	public ModelAndView annualStatement(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("views/statement/annualStatement");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy");
		mv.addObject("annualStatements",findAnnualStatements(sf.format(new Date())));
		return mv; 
	}
	/**
	 * 年度报表数据
	 * @param year
	 * @return
	 */
	@RequestMapping(value="findAnnualStatements",method=RequestMethod.POST)
	@ResponseBody
	public String findAnnualStatements(@RequestParam(defaultValue="2017",value="year")String year){
		List<HouseStatement> annualStatements =  houseStatementService.findAnnualHouseStatement(year);
		return JsonUtils.objectToJson(annualStatements);
	}
	
	/**
	 * 月度报表
	 * @return
	 */
	@RequestMapping(value="monthStatement")
	public ModelAndView monthStatement(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("views/statement/monthStatement");
		List<HouseStatement> monthStatement =  houseStatementService.findMonthHouseStatement("2017", "01");
		mv.addObject("monthStatement",monthStatement);
		return mv; 
	}
	
	/**
	 * 月度报表数据
	 * @param year
	 * @return
	 */
	@RequestMapping(value="findMonthStatements",method=RequestMethod.POST)
	@ResponseBody
	public String findMonthStatements(@RequestParam(defaultValue="2017",value="year")String year){
		List<HouseStatement> monthStatements =  houseStatementService.findMonthHouseStatement(year, "01");
		return JsonUtils.objectToJson(monthStatements);
	}
	

}
